package com.aruba.attendance.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.aruba.attendance.database.entity.RecordEntity
import kotlinx.coroutines.flow.Flow

/**
 * 打卡记录的Dao层
 * Created by aruba on 2023/2/15.
 */
@Dao
interface RecordDao {
    @Insert
    suspend fun insert(recordEntity: RecordEntity)

    //根据年月日查询
    @Query("SELECT * FROM RecordEntity WHERE year = :year and month = :month and dayOfMonth = :dayOfMonth")
    fun findRecordFlowByDate(year: Int, month: Int, dayOfMonth: Int): Flow<List<RecordEntity>>

    @Query("SELECT * FROM RecordEntity WHERE year = :year and month = :month and dayOfMonth = :dayOfMonth")
    suspend fun findRecordByDate(year: Int, month: Int, dayOfMonth: Int): List<RecordEntity>

    @Update
    suspend fun updateRecordById(recordEntity: RecordEntity)

    @Query("DELETE FROM RecordEntity")
    suspend fun clear()
}